import {isUrl} from '../util/util';

const menuData = [{
  name: '环境',
  icon: 'star',
  path: 'env'
}, {
  name: '应用',
  icon: 'star',
  path: 'app'
}, {
  name: '部署',
  icon: 'star',
  path: 'deploy'
},{
  name: '版本信息',
  icon: 'star',
  path: 'versionInfo'
}];

function formatter(data, parentPath = '/', parentAuthority) {
  return data.map((item) => {
    let {path} = item;
    if (!isUrl(path)) {
      path = parentPath + item.path;
    }
    const result = {
      ...item,
      path,
      authority: item.authority || parentAuthority,
    };
    if (item.children) {
      result.children = formatter(item.children, `${parentPath}${item.path}/`, item.authority);
    }
    return result;
  });
}

const getMenuData = () => formatter(menuData);

export default getMenuData;
